<!DOCTYPE html>
<html lang="en">
<head>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <title>test</title>
        <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.js"></script>
    </head>
</head>
<body>
<div>
    <button onclick="test(1)" style="width: 100px;height: 60px;">男人</button>
    <span id="a1"></span>
    <button onclick="test(2)" style="width: 100px;height: 60px;">女人</button>
    <span id="a2"></span>
</div>
<br/>
<br/>
<br/>
<div>
    <button onclick="test(3)" style="width: 100px;height: 60px;">老年人</button>
    <span id="a3"></span>
    <button onclick="test(4)" style="width: 100px;height: 60px;">年轻人</button>
    <span id="a4"></span>
    <button onclick="test(5)" style="width: 100px;height: 60px;">小孩</button>
    <span id="a5"></span>
</div>
</body>
<script>

    // test2();

    function test(id) {
        var oAjax = getAjax();
        //post方式打开文件
        oAjax.open('get', 'http://120.78.90.0:8000/test/v1/update/' + id + '?a=' + Math.random(), true);
        //post发送数据
        oAjax.send(null);
        oAjax.onreadystatechange = function () {
            var oAjax2 = getAjax();
            //post方式打开文件
            oAjax2.open('get', 'http://120.78.90.0:8000/test/v1/get/' + id + '?a=' + Math.random(), true);
            //post发送数据
            oAjax2.send(null);
            oAjax2.onreadystatechange = function () {
                //当状态为4的时候，执行以下操作
                if (oAjax2.readyState == 4) {
                    try {
                        //alert(oAjax2.responseText);
                        document.getElementById("a"+id).innerText = oAjax2.responseText;
                    } catch (e) {
                    }
                    ;
                }
                ;
            };
        };


    }

    function getAjax() {
        var oAjax = null;
        //这里进行HTTP请求
        try {
            oAjax = new XMLHttpRequest();
        } catch (e) {
            oAjax = new ActiveXObject("Microsoft.XMLHTTP");
        }
        ;
        return oAjax;
    }

</script>
</html>